<?php

class OPRock {
	/**
	* -------------------------------------------------------------------------
	*
	* 									Attributes
	*
	* -------------------------------------------------------------------------
	*/
	
	/**
	 * Id of the rock
	 * 
	 * @var int
	 */
	protected $id = null;
	
	/**
	* Position of the rock
	*
	* @var OPPosition
	*/
	protected $position;
	
	/**
	* Number of players needed to move the rock
	*
	* @var int
	*/
	protected $numberOfPlayersToMove;
	
	/**
	 * -------------------------------------------------------------------------
	 * 
	 * 									Static
	 * 
	 * -------------------------------------------------------------------------
	 */
	
	/**
	* Static constructor creating a new Rock with a position
	*
	* @param $position, $numberOfPlayersToMove
	* @return OPRock
	*/
	public static function newWithPositionAndANumberOfPlayersToMove($position, $numberOfPlayersToMove){
		$newRock = new OPRock();
		$newRock->setPosition($position);
		$newRock->setNumberOfPlayersToMove($numberOfPlayersToMove);
	
		return $newRock;
	
	}
	
	/**
	* -------------------------------------------------------------------------
	*
	* 									Dynamic
	*
	* -------------------------------------------------------------------------
	*/
	
	/**
	* -------------------------------------------------------------------------
	* 									Setters
	* -------------------------------------------------------------------------
	*/
	
	/**
	* Set rock's position
	*
	* @param $position
	* @return OPRock
	*/
	public function setPosition($position) {
		$this->position = $position;
	
		return $this;
	
	}
	
	/**
	* Set rock's number of players to move
	*
	* @param $numberOfPlayersToMove
	* @return OPRock
	*/
	public function setNumberOfPlayersToMove($numberOfPlayersToMove) {
		$this->numberOfPlayersToMove = $numberOfPlayersToMove;
	
		return $this;
	
	}
	
	/**
	* -------------------------------------------------------------------------
	* 									Getters
	* -------------------------------------------------------------------------
	*/
	
	/**
	 * Return the id of the rock
	 * 
	 * @return int
	 */
	public function id() {
		return $this->id;
		
	}
	
	/**
	* Return the position of the rock
	*
	* @return OPPosition
	*/
	public function position() {
		return $this->position;
	
	}
	
	/**
	 * Return the number of players needed to move the rock
	 * 
	 * @return int
	 */
	public function numberOfPlayersToMove() {
		return $this->numberOfPlayersToMove;
		
	}
	
	/**
	 * Return the number of players arround the rock
	 * 
	 * @return int
	 */
	public function numberOfPlayersArround() {
		var_dump(count(OPPlayer::playersArround($this->position())));
		return count(OPPlayer::playersArround($this->position()));
		
	}
	
	/**
	* -------------------------------------------------------------------------
	* 									Testing
	* -------------------------------------------------------------------------
	*/
	
	/**
	 * Return true if the rock can move
	 * 
	 * @return boolean
	 */
	public function canMove() {
		return $this->numberOfPlayersToMove() <= $this->numberOfPlayersArround();
		
	}
	
	/**
	* -------------------------------------------------------------------------
	* 									OPIDatabase
	* -------------------------------------------------------------------------
	*/
	
	public function save() {
		OPDatabase::saveRock($this);
		
	}
}